﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Collections;



public class lists : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        // paramJson: {"onlyId":2313,"memberId":21,"pageNo":1,"pageSize":99}
        Uri uri = HttpContext.Current.Request.Url;
        String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
        var xxx=HttpContext.Current.Request.Form["paramJson"];
        JObject jo = (JObject)JsonConvert.DeserializeObject(xxx);



        string tid = jo["tid"].ToString();
        string bid = jo["bid"].ToString();
        string id = "1";

        if (string.IsNullOrEmpty(id))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "获取成功";
        var time = DateTime.Now;


        using (Entities bll = new Entities())
        {
            int _id = int.Parse(tid);
            var x = bll.S_Goods.SingleOrDefault(xx => xx.GID == _id);
            var imgs = methods.GetImgs(x.GImg);


            var Bpl = bll.P_Task.Where(xx=>xx.PointID==x.GID).ToList();//全部.ToList();

            ArrayList listjson = new ArrayList();
            foreach (var myda in Bpl)
            {
                 var myimgs = methods.GetImgs(myda.TImg);
                listjson.Add(new
                {
                    id=myda.TID,
                    name=myda.TName,
                    latitude = x.Glatitude,
                    longitude = x.Glongitude,
                    iconPath = "/img/ico/st.png",
                    width=30,
                    height=30,
                    img=myimgs,
                    description=myda.Tintroduce

                });

            };


             var ptdetail = bll.P_T_Detail.OrderByDescending(xx=>xx.id).ToList();//全部.ToList();

            ArrayList listTaskDetail = new ArrayList();
            foreach (var myda in ptdetail)
            {
                 var myimgs = methods.GetImgs(myda.content_images);
                listTaskDetail.Add(new
                {
                    id=myda.id,
                    content_images=myimgs,
                    myda.content_text,
                    creattime=myda.addtime,
                    myda.State,
                    user=methods.getUserNickname(myda.UserId)

                });

            };




            var data = new
            {
                Sname= x.GName,
                id = x.GID,
                text = x.GContent.Replace("src=\"/upload/","src=\""+host+"/upload/"),
                introu = x.G_Introduce,
                img = imgs,
                x.Glatitude,
                x.Glongitude,
                x.Gaddress,
                task=listjson,
                scale = 6,  //比例尺10-16
                      tel=x.Gtel,
                time=x.GStartTime+ x.GEndTime,
                addre=x.Gaddress,
                listTaskDetail,

            };



            //全部.ToList();
            context.Response.Write(JsonConvert.SerializeObject(new { code, msg, time, data }));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }




}